<%= fields_for "product[property_group_attributes][properties_attributes][#{@product.property_group.properties.count - 1}]", @property do |property| %>  
  <li class="property">
    <div>
      <%= property.label :presentation %> <%= property.autocomplete_field :presentation, autocomplete_property_presentation_admin_properties_path, :class => "property_presentation", :maxlength => 35, :node_id => property.object.id %>
      <%= property.hidden_field :position, :class => "property_position" %>
      
      <%= property.hidden_field :id %>
      
      <span style="float: right"><%= link_to_remove_fields("Smazat skupinu", property, "property") %></span>
    </div>

    <ol class="property_attributes" id="<%= "#{dom_id(property.object, :product_property_attribute_new)}"%>">
      <%= property.fields_for :property_attributes, @property_attribute do |property_attribute| %>
        <li class="property_attribute">
          <div>
            <%= property_attribute.label :presentation %>
            <%= property_attribute.text_field :presentation, :class => "property_attribute_presentation", :maxlength => 35, :size => 16, :node_id => property_attribute.object.id %>

            <%= property_attribute.hidden_field :id %>
            
            <%= property_attribute.hidden_field :node_parent_id, :class => "property_attribute_parent_id", :size => 4 %>
            <%= property_attribute.hidden_field :node_next_id, :class => "property_attribute_next_id", :size => 4 %>
            <%= property_attribute.hidden_field :node_prev_id, :class => "property_attribute_prev_id", :size => 4 %>
            <%= property_attribute.hidden_field :node_id, :class => "property_attribute_node_id", :size => 4, :value => property_attribute.object.id %>

            <%= property_attribute.fields_for :property_value do |property_value| %>
              <%= property_value.label :value %>
              <%= property_value.text_field :value, :class => "property_value_value", :maxlength => 60, :size => 20 %>

              <%= property_value.collection_select :metric_id, Metric.all, :id, :presentation, :include_blank => true %>
            <% end %>

            <span style="float: right;"><%= link_to_remove_fields("Smazat vlastnost", property_attribute, "property_attribute") %></span>
          </div>
        </li>
      <% end %>
    </ol>

    <%= spinner "#{dom_id(property.object, :product_property_attribute)}" %>
    <%= link_to 'Přidat vlastnost', new_property_attribute_admin_product_product_properties_path(params[:product_id], :property_id => property.object.id), :class => "new_button", :id => "#{dom_id(property.object, :product_property_attribute_button)}", :remote => true, :style => "width: 140px;" %>
  </li>

  <script type="text/javascript">
    jQuery(function() {
      init_properties_sortable();

      var toggleSpinner = function() {$("#<%= "#{dom_id(property.object, :product_property_attribute)}" %>").toggle()};

      $("#<%= "#{dom_id(property.object, :product_property_attribute_button)}" %>")
        .bind("ajax:beforeSend", toggleSpinner)
        .bind("ajax:complete", toggleSpinner);
    });
  </script>
<% end %>